package test2;

class Node<K>{

    K data;

    Node<K> nextNode;
}

public class Stack<K> {

    public Node<K> head;

    public int length;

    public void push(K item){
        Node<K> node = new Node<K>();
        node.data = item;
        node.nextNode = head;
        head = node;
        length++;
    }

    public K pop(){
        if(head == null)
            return null;
        Node<K> temp = head;
        head = head.nextNode;
        length--;
        return temp.data;
    }

}
